package com.app.service.impl;

import com.app.mapper.ComRecruitersMapper;
import com.app.mapper.QuestionnaireHelpMapper;
import com.app.model.ComRecruitersModel;
import com.app.model.JobFairSceneModel;
import com.app.model.QuestionnaireHelpModel;
import com.app.model.ShareCircleAtlasModel;
import com.app.service.ComRecruitersService;
import com.app.service.EnterpriseService;
import com.app.service.QuestionnaireHelpService;
import com.app.service.UserService;
import com.app.util.StringTool;
import com.app.vo.ComRecruitersVo;
import com.app.vo.QuestionnaireHelpVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @Description:帮扶实现类
 * @Author: N
 * @Date: 2022年11月24日 10点29分
 */
@Service
public class QuestionnaireHelpServiceImpl implements QuestionnaireHelpService {

    @Autowired
    QuestionnaireHelpMapper questionnaireHelpMapper;


    @Override
    public int insert(QuestionnaireHelpModel model) {
        return questionnaireHelpMapper.insert(model);
    }

    @Override
    public void update(QuestionnaireHelpModel model) {
        questionnaireHelpMapper.updateById(model);
    }

    @Override
    public void delete(Integer id) {
        questionnaireHelpMapper.deleteById(id);
    }

    @Override
    public QuestionnaireHelpModel getModelById(Integer id) {
        return questionnaireHelpMapper.selectById(id);
    }

    @Override
    public List<QuestionnaireHelpModel> getModelByUserId(Integer userId) {
        QueryWrapper<QuestionnaireHelpModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("state",1);
        return questionnaireHelpMapper.selectList(queryWrapper);
    }

    @Override
    public QuestionnaireHelpVo getModelByPage(QuestionnaireHelpModel model) {
        QueryWrapper<QuestionnaireHelpModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",model.getUserId());
        queryWrapper.eq("state",1);
        queryWrapper.orderByDesc("crt_time");
        Page<QuestionnaireHelpModel> page = new Page<>();
        page.setCurrent(model.getPage());
        page.setSize(model.getLimit());
        Page<QuestionnaireHelpModel> pages = questionnaireHelpMapper.selectPage(page,queryWrapper);
        for (int i = 0; i < pages.getRecords().size(); i++) {

            if(pages.getRecords().get(i).getState()!=null&&pages.getRecords().get(i).getState()==2)
            {
                pages.getRecords().get(i).setIsWorkText("是");
            }else{
                pages.getRecords().get(i).setIsWorkText("否");
            }
        }
        QuestionnaireHelpVo vo = new QuestionnaireHelpVo();
        vo.setCount((int)pages.getTotal());
        vo.setList(pages.getRecords());
        return vo;

    }

    @Override
    public QuestionnaireHelpModel getModel(QuestionnaireHelpModel model) {
        QueryWrapper<QuestionnaireHelpModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",model.getUserId());
        queryWrapper.eq("state",2);
        List<QuestionnaireHelpModel> userList = questionnaireHelpMapper.selectList(queryWrapper);
        if (userList==null||userList.isEmpty()) {
            return null;
        } else {
            return userList.get(0);
        }
    }
}
